package com.tjw.ec.upms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tjw.ec.common.core.util.PageUtils;
import com.tjw.ec.common.core.util.Query;
import com.tjw.ec.upms.api.entity.UserAccountEntity;
import com.tjw.ec.upms.dao.UserAccountDao;
import com.tjw.ec.upms.service.UserAccountService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 用户登陆信息表
 *
 * @author T-junwen
 * @email t-junwen@foxmail.com
 * @date 2019-07-27 16:43:31
 */
@Slf4j
@Service("userAccountService")
public class UserAccountServiceImpl extends ServiceImpl<UserAccountDao, UserAccountEntity> implements UserAccountService {

    @Override
    public PageUtils<UserAccountEntity> queryPage(Map<String, Object> params) {

        IPage<UserAccountEntity> page = new Query<UserAccountEntity>(params).getPage();

        QueryWrapper<UserAccountEntity> queryWrapper = new QueryWrapper<>();

        IPage<UserAccountEntity> data = baseMapper.selectPage(
                page,
                queryWrapper
        );

        return new PageUtils(data);
    }

    /**
     * @param username
     * @Title: 根据账号查询用户账户信息
     * @Param: []
     * @return: void
     * @Author: 田俊文
     * @Date: 2019/8/2 13:48
     * @Throws:
     */
    @Override
    public UserAccountEntity getUserAccountByUsername(String username) {
        log.error("查询用户信息");
        if (StringUtils.isEmpty(username)){
            return null;
        }
        QueryWrapper<UserAccountEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("username",username);
        UserAccountEntity userAccountEntity = baseMapper.selectOne(queryWrapper);
        return userAccountEntity;
    }

}
